<template>
  <el-card shadow="hover" style="margin: 10px;">
        <el-alert
            class="warn-content"
            title="温馨提示"
            type="success"
            show-icon
            :closable="false">
               本系统使用到
               <a href="https://developer.open-douyin.com/" target="_blank">《抖音开放平台》</a>
          </el-alert>
          <br/>
      <el-form ref="form" :rules="rules" :model="config"  label-width="120px" label-position="right" style="width: 60%;">
        <el-form-item label="应用名称" prop="appName">
           <el-input v-model="config.appName"></el-input>
         </el-form-item>
         <el-form-item label="抖音clientKey" prop="clientKey">
            <el-input v-model="config.clientKey"></el-input>
          </el-form-item>
          <el-form-item label="抖音clientSecret" prop="clientSecret">
            <el-input type="password" autocomplete="off" v-model="config.clientSecret"></el-input>
          </el-form-item>
         <el-form-item label="回调地址" prop="redirectUrl">
           <el-input v-model="config.redirectUrl"></el-input>
         </el-form-item>
         <el-form-item label="权限域" prop="scope">
           <el-input v-model="config.scope"></el-input>
         </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="updateConfig">更新配置</el-button>
        </el-form-item>
      </el-form>
  </el-card>

</template>

<style scoped="scoped">
  ::v-deep .line {
    text-align: center;
  }
</style>
<script>

import { getDouyinConfig, updateDouyinConfig } from '@/api/third'
export default {
  name: 'weixinConfig',
  data() {
    return {
			config:{},
			loading : true,
      rules: {
        appName: [{ required: true, message: '请填写应用名称', trigger: 'blur' }],
        clientKey: [{ required: true, message: '请填写clientKey', trigger: 'blur' }],
        clientSecret: [{ required: true, message: '请填写clientSecret', trigger: 'blur' }],
        redirectUrl: [{ required: true, message: '请填写回调地址', trigger: 'blur' }],
        scope: [{ required: true, message: '请填写权限域', trigger: 'blur' }],
      }
    }
  },
  created() {
    this.get()
  },
  methods: {
    get() {
      getDouyinConfig().then(response => {
        this.config = response.data
        if(!this.config) this.config = {}
    		this.loading = false
      })
    },
    updateConfig() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
    			var formData = Object.assign({}, this.config);
    			formData.addTime = null
    			formData.updTime = null
          updateDouyinConfig(formData).then(() => {
            this.$notify({
              title: '成功',
              message: '更改配置成功',
              type: 'success',
              duration: 2000
            })
          })
        }
      })
    },
  }
}
</script>
